<template>
  <div>
    <Form label-position="right" :label-width="400" :model="jobItem">
      <Row class="mb20">
        <Col span="5" class="ivu-form-item-label">身份证号码：</Col>
        <Col span="6" class="ivu-form-item-content">
          <Input v-model="jobItem.aac002" placeholder="请输入身份证号码"></Input>
        </Col>
        <Col span="5" class="ivu-form-item-label">姓名：</Col>
        <Col span="6" class="ivu-form-item-content">
          <Input v-model="jobItem.aac003" placeholder="请输入姓名"></Input>
        </Col>
      </Row>
      <Row class="mb20">
        <Col span="5" class="ivu-form-item-label">民族：</Col>
        <Col span="6" class="ivu-form-item-content">
          <Select v-model="jobItem.aac005" style="width:218px">
            <Option v-for="item in mzList" :value="item.value" :key="item.value">{{ item.label }}</Option>
          </Select>
        </Col>
        <Col span="5" class="ivu-form-item-label">政治面貌：</Col>
        <Col span="6" class="ivu-form-item-content">
          <Select v-model="jobItem.aac024" style="width:218px">
            <Option v-for="item in zzList" :value="item.value" :key="item.value">{{ item.label }}</Option>
          </Select>
        </Col>
      </Row>
      <Row class="mb20">
        <Col span="5" class="ivu-form-item-label">文化程度：</Col>
        <Col span="6" class="ivu-form-item-content">
          <Select v-model="jobItem.aac011" style="width:218px">
            <Option v-for="item in whList" :value="item.value" :key="item.value">{{ item.label }}</Option>
          </Select>
        </Col>
        <Col span="5" class="ivu-form-item-label">所学专业：</Col>
        <Col span="6" class="ivu-form-item-content">
          <Select v-model="jobItem.aac183" style="width:218px" >
            <Option v-for="item in zyList" :value="item.id" :key="item.id">{{ item.label }}</Option>
          </Select>
        </Col>
      </Row>
      <Row class="mb20">
        <Col span="5" class="ivu-form-item-label">毕业学校：</Col>
        <Col span="6" class="ivu-form-item-content">
          <Input v-model="jobItem.aac180" placeholder="请输入毕业学校"></Input>
        </Col>
        <Col span="5" class="ivu-form-item-label">健康状况：</Col>
        <Col span="6" class="ivu-form-item-content">
          <Select v-model="jobItem.aac033" style="width:218px">
            <Option v-for="item in jkList" :value="item.value" :key="item.value">{{ item.label }}</Option>
          </Select>
        </Col>
      </Row>
      <Row class="mb20">
        <Col span="5" class="ivu-form-item-label">居住地址：</Col>
        <Col span="6" class="ivu-form-item-content">
          <Input v-model="jobItem.aae066" placeholder="请输入居住地址"></Input>
        </Col>
        <Col span="5" class="ivu-form-item-label">电子邮件：</Col>
        <Col span="6" class="ivu-form-item-content">
          <Input v-model="jobItem.aae015" placeholder="请输入电子邮件"></Input>
        </Col>
      </Row>
      <Row class="mb20">
        <Col span="5" class="ivu-form-item-label">手机1：</Col>
        <Col span="6" class="ivu-form-item-content">
          <Input v-model="jobItem.aae005a" placeholder="请输入手机号"></Input>
        </Col>
        <Col span="5" class="ivu-form-item-label">手机2：</Col>
        <Col span="6" class="ivu-form-item-content">
          <Input v-model="jobItem.aae005b" placeholder="请输入手机号"></Input>
        </Col>
      </Row>
      <Row class="mb20">
        <Col span="5" class="ivu-form-item-label">座机：</Col>
        <Col span="6" class="ivu-form-item-content">
          <Input v-model="jobItem.aae005c" placeholder="请输入座机号"></Input>
        </Col>
      </Row>
      <Row class="mb20"
           v-for="(item, index) in jobHunting.items"
           :key="index">
        <Col span="5" class="ivu-form-item-label">求职岗位：</Col>
        <Col span="6" class="ivu-form-item-content">
          <Select v-model="item.position" @on-open-change="Occupation"  placeholder="职业（工种）">
            <Option v-for="item in OccupationList" :value="item.aca111" :key="item.aca111">{{ item.aca112 }}</Option>
          </Select>
<!--          <Input v-model="item.position" placeholder="请输入求职岗位"></Input>-->
        </Col>
        <Col span="5" class="ivu-form-item-label">工资要求：</Col>
        <Col span="6" class="ivu-form-item-content">
          <Input v-model="item.salary" placeholder="请输入工资要求"></Input>
        </Col>
      </Row>
      <Row class="mb20">
        <Col span="3">
          <Button type="dashed" long @click="handleAdd1" icon="md-add">添加岗位</Button>
        </Col>
      </Row>
      <Row v-for="(item, index) in formDynamic.items"
           :key="index + 100">
        <Col span="2" class="ivu-form-item-label">工作单位：</Col>
        <Col span="4" class="ivu-form-item-content">
          <Input v-model="item.company" placeholder="请输入工作单位"></Input>
        </Col>
        <Col span="2" class="ivu-form-item-label">开始时间：</Col>
        <Col span="4" class="ivu-form-item-content">
          <DatePicker v-model="item.stime" type="date" format="yyyy-MM-dd" placeholder="请选择开始时间" style="width: 140px"></DatePicker>
        </Col>
        <Col span="2" class="ivu-form-item-label">结束时间：</Col>
        <Col span="4" class="ivu-form-item-content">
          <DatePicker v-model="item.etime" type="date" format="yyyy-MM-dd" placeholder="请选择结束时间" style="width: 140px"></DatePicker>
        </Col>
        <Col span="2" class="ivu-form-item-label">岗位名称：</Col>
        <Col span="4" class="ivu-form-item-content">
          <Input v-model="item.post" placeholder="请输入岗位名称"></Input>
        </Col>
      </Row>
      <Row class="mb20">
        <Col span="3">
          <Button type="dashed" long @click="handleAdd" icon="md-add">添加经历</Button>
        </Col>
      </Row>
    </Form>
  </div>
</template>

<script>
import itemdata from '../itemdata'
import { date2str } from '@/api/eventlist'
import { createPost } from '@/api/post'
export default {
  props: {
    unemploymentItem12: Object
  },
  name: 'index.vue',
  data () {
    return {
      aa: '',
      index: 1,
      index1: 1,
      jobHunting: {
        items: [
          {
            position: '',
            salary: '',
            index: 1
          }
        ]
      },
      formDynamic: {
        items: [
          {
            company: '',
            stime: '',
            etime: '',
            post: '',
            index: 1
          }
        ]
      },
      mzList: itemdata.nationList,
      zzList: itemdata.politicalOutlookList,
      whList: itemdata.educationList,
      zyList: [],
      jkList: itemdata.physicalConditionList,
      OccupationList: [],
      jobItem: {
        apiName: 'sq4grqzdj',
        aac002: '',
        aac003: '',
        aac005: '',
        aac024: '',
        aac011: '',
        aac183: '',
        aac180: '',
        aac033: '',
        aae066: '',
        aae015: '',
        aae005a: '',
        aae005b: '',
        aae005c: '',
        qzyy: [],
        gzjl: []
      }
    }
  },
  watch: {
    // 回显
    unemploymentItem12 (a) {
      this.jobItem = a
      let gzjl = []
      let qzyy = []
      this.jobItem.gzjl.forEach(item => {
        let data1 = {
          company: item.dwname,
          stime: date2str(item.gstartdate),
          etime: date2str(item.genddate),
          post: item.gwname
        }
        gzjl.push(data1)
      })
      this.formDynamic.items = gzjl
      this.jobItem.qzyy.forEach(item => {
        let data1 = {
          position: item.acb216,
          salary: item.acb21h
        }
        qzyy.push(data1)
      })
      this.jobHunting.items = qzyy
      console.log(this.jobHunting.items)
    }
  },
  methods: {
    // 选择取得职业（工种）资格代码
    Occupation () {
      let param = {
        apiName: 'sq4gjzyfl'
      }
      createPost(param).then(ret => {
        if (ret.data.data.result === '1') {
          this.OccupationList = ret.data.data.data
        }
      })
    },
    // 所学专业
    findZYList () {
      let data = {
        apiName: 'sq4zycode'
      }
      createPost(data).then(ret => {
        this.zyList = ret.data.data.data
        /* if (ret.data.result === '1') {

        } else if (ret.data.result === '0') {
          this.$Notice.error({ title: ret.data.errmsg, desc: '' })
        } */
      })
    },
    test () {
      this.jobItem.qzyy = []
      this.jobItem.gzjl = []
      let reg = /(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}$)/
      let reg1 = /^1[3456789]\d{9}$/
      if (this.jobItem.aac183 === '' || this.jobItem.aac183 === undefined) {
        this.$Notice.error({ title: '请选择所学专业', desc: '' })
        return false
      }
      // 添加工作岗位
      for (let i = 0; i < this.jobHunting.items.length; i++) {
        let data1 = {
          acb216: this.jobHunting.items[i].position,
          acb21h: this.jobHunting.items[i].salary
        }
        this.jobItem.qzyy.push(data1)
      }
      // 添加经历
      for (let i = 0; i < this.formDynamic.items.length; i++) {
        let data1 = {
          dwname: this.formDynamic.items[i].company,
          gstartdate: date2str(this.formDynamic.items[i].stime),
          genddate: date2str(this.formDynamic.items[i].etime),
          gwname: this.formDynamic.items[i].post
        }
        this.jobItem.gzjl.push(data1)
      }
      if (reg.test(this.jobItem.aac002) === false) {
        this.$Notice.error({ title: '身份证不合法', desc: '' })
        return false
      } else if (this.jobItem.aac003 === '' || this.jobItem.aac003 === undefined) {
        this.$Notice.error({ title: '请输入姓名', desc: '' })
        return false
      } else if (this.jobItem.aac005 === '' || this.jobItem.aac005 === undefined) {
        this.$Notice.error({ title: '请选择民族', desc: '' })
        return false
      } else if (this.jobItem.aac024 === '' || this.jobItem.aac024 === undefined) {
        this.$Notice.error({ title: '请选择政治面貌', desc: '' })
        return false
      } else if (this.jobItem.aac011 === '' || this.jobItem.aac011 === undefined) {
        this.$Notice.error({ title: '请选择文化程度', desc: '' })
        return false
      } else if (this.jobItem.aac180 === '' || this.jobItem.aac180 === undefined) {
        this.$Notice.error({ title: '请输入毕业院校', desc: '' })
        return false
      } else if (this.jobItem.aac033 === '' || this.jobItem.aac033 === undefined) {
        this.$Notice.error({ title: '请选择健康状况', desc: '' })
        return false
      } else if (this.jobItem.aae066 === '' || this.jobItem.aae066 === undefined) {
        this.$Notice.error({ title: '请输入居住地址', desc: '' })
        return false
      } else if (reg1.test(this.jobItem.aae005a) === false) {
        this.$Notice.error({ title: '手机号1不合法', desc: '' })
        return false
      } else if (this.jobHunting.items[0].position === '' || this.jobHunting.items[0].position === undefined) {
        this.$Notice.error({ title: '请输入求职岗位', desc: '' })
        return false
      } else if (this.jobHunting.items[0].salary === '' || this.jobHunting.items[0].salary === undefined) {
        this.$Notice.error({ title: '请输入工资要求', desc: '' })
        return false
      } else {
        this.$emit('jobItem', this.jobItem)
      }
    },
    // 添加工作经验
    handleAdd () {
      this.index++
      this.formDynamic.items.push({
        company: '',
        stime: '',
        etime: '',
        post: '',
        index: this.index
      })
    },
    handleAdd1 () {
      this.index1++
      this.jobHunting.items.push({
        position: '',
        salary: '',
        index: this.index1
      })
    }
  },
  mounted () {
    this.findZYList()
  }
}
</script>

<style scoped>
  .ivu-row{
    margin-bottom: 15px;
  }
</style>
